# coding: utf-8
from typing import List, Callable
from PySide6.QtCore import Qt
from PySide6.QtWidgets import QApplication, QWidget
from qfluentwidgets import ScrollArea, FlowLayout

from qelwidgets import ElImageLabel, CentreImageLabel, UploadImageLabel


class Demo(ScrollArea):
    def __init__(self):
        super().__init__()
        self.view = QWidget()
        self.flowLayout = FlowLayout(self.view)
        self.__initWidgets()
        self.initImages()

    def __initWidgets(self):
        self.setWidget(self.view)
        self.setWidgetResizable(True)
        self.view.setAutoFillBackground(True)
        self.enableTransparentBackground()
        self.resize(1000, 700)

    def initImages(self):
        urls = [
            'https://i0.hdslb.com/bfs/article/49b9240d91cd233adb878f316b88cee73d51828f.jpg',
            'http://gd-hbimg.huaban.com/319e4c01dd966cf2626af0d5449f3f3f254014ce258774-BhSHkW',
            'https://gd-hbimg.huaban.com/41a5264343cc03568e0fa239991f3a268ec1cbc2d46b0c-Dn3S8Y',
            'http://hbimg.huaban.com/e781a742735b2e8a9ba75e9d5ce5151ac6befcb3420e4f-rTBmXX',
            'https://gd-hbimg.huaban.com/522bf176ac4887b0c4b120d4a67a752231f80acc16e88f-KEgQ6g',
        ]
        for url in urls[0:2]:
            self.createImageLabel(url, CentreImageLabel)
        for url in urls[2:4]:
            self.createImageLabel(url, ElImageLabel)

        self.createImageLabel(urls[4], UploadImageLabel)

    def createImageLabel(self, url: str, labelType: Callable):
        label = labelType(self)
        label.setUrl(url)
        label.setFixedSize(300, 200)
        label.finished.connect(lambda: label.scaledToHeight(200))
        label.setBorderRadius(8, 8, 8, 8)
        self.flowLayout.addWidget(label)


if __name__ == '__main__':
    app = QApplication([])
    demo = Demo()
    demo.resize(1000, 700)
    demo.setStyleSheet("background-color: #ffffff;")
    demo.show()
    app.exec()
